<template>
  <div class="box">
    <el-pagination background layout="sizes,prev, pager, next, jumper" :total="total" :page-sizes="[2, 6, 10, 20]" @size-change="sizeChange" @current-change="currentChange"></el-pagination>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="id" label="ID" width="140"></el-table-column>
      <el-table-column label="图" width="360">
        <template slot-scope="scope">
          <img v-if="scope.row.cover[0].url" :src="scope.row.cover[0].url" alt />
          <img v-else src="@/assets/logo.png" alt />
        </template>
      </el-table-column>
      <el-table-column prop="title" label="标题" width="200"></el-table-column>
      <el-table-column label="时间">
        <!-- 自定义的渲染内容 -->
        <template slot-scope="scope">{{scope.row.create_date.split('T')[0]}}</template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      total:0,
      page:{
          pageIndex:1,
          pageSize:10
      }
    };
  },
  created() {
    this.acquire()   //获取文章
  },
  methods:{
      acquire(){  //获取文章
        this.$axios({
            url: "/post",
            params:this.page
            }).then((res) => {
            console.log(res);
            this.tableData = res.data.data;
            this.total = res.data.total
        });
      },

      sizeChange(size){
          this.page.pageSize = size
          this.acquire()
      },
      currentChange(current){
          this.page.pageIndex = current
          this.acquire()
      }
  }
};
</script>

<style lang="less" scoped>
.box {
  img {
    max-height: 146px;
  }
}
</style>